Skip to content

Refactored GlobalActorIsolation type#15

Merged
NSFatalError merged 6 commits into
mainfrom
feature/global-actor-isolation-refactor
Aug 18, 2025
Merged

Refactored GlobalActorIsolation type#15
NSFatalError merged 6 commits into
mainfrom
feature/global-actor-isolation-refactor

Conversation

@NSFatalError

@NSFatalError NSFatalError commented Aug 18, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Exposed an attribute for inherited global actor isolation on declarations.
  • Refactor

    • Renamed public APIs to improve clarity around access control inheritance, explicit global actor isolation, and trimmed type access.
    • Standardized enum associated value labeling for extension contexts.
    • Adjusted global actor attribute formatting for consistent spacing.
  • Tests

    • Updated expectations to validate type-based global actor isolation instead of attribute-based checks.

@NSFatalError NSFatalError self-assigned this Aug 18, 2025
@coderabbitai

coderabbitai Bot commented Aug 18, 2025

Copy link
Copy Markdown

Walkthrough

This PR renames several public APIs, adjusts access-control and global-actor isolation derivation, updates enum associated labels, and aligns tests. Key updates include switching to inlinableAccessControlLevel, adopting explicitGlobalActorIsolation, exposing inheritedGlobalActorAttribute, and standardizing on trimmedType across type-builder contexts.

Changes

Cohort / File(s) Summary
Access control API rename
Sources/PrincipleMacros/Syntax/Extensions/WithModifiersSyntax.swift, Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift
Renamed accessControlLevel(...) to inlinableAccessControlLevel(...); updated DeclBuilder to use the new API for inherited access control.
Global actor isolation propagation
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift, Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilderSettings.swift, Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift, Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift
Switched from preferredGlobalActorIsolation to explicitGlobalActorIsolation; revised derivation to favor explicit setting, otherwise infer from declaration; exposed inheritedGlobalActorAttribute via inlinable attribute; tests now validate type-based isolation.
Type builder naming/labels
Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilder.swift, Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilderContext.swift
Renamed trimmedTypeName → trimmedType; changed enum case to labeled associated value extension(trimmedType:); updated pattern matches and context passing accordingly.
Minor structural reorg
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift
Split into two extensions without functional impact.

Sequence Diagram(s)

sequenceDiagram
  actor Client
  participant DeclBuilder
  participant Settings as DeclBuilderSettings
  participant Modifiers as WithModifiersSyntax
  participant Isolation as GlobalActorIsolation

  Client->>DeclBuilder: build(...)
  DeclBuilder->>Settings: read explicitGlobalActorIsolation
  alt explicit set
    DeclBuilder->>Isolation: use explicit isolation
  else not set
    DeclBuilder->>DeclBuilder: derive from basicDeclaration.globalActor
    DeclBuilder->>Isolation: .isolated(trimmedType: ...)
  end
  DeclBuilder->>Modifiers: inlinableAccessControlLevel(inheritedBy:maxAllowed:)
  Modifiers-->>DeclBuilder: TokenSyntax?
  Isolation-->>DeclBuilder: inlinableAttribute?
  DeclBuilder-->>Client: built declaration + attributes/modifiers
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

A nib of code, a hop of fate,
I trimmed my types and labeled state.
Actors global, neatly placed,
Access inlined, no time to waste.
Thump goes CI—green and bright,
Carrot-shaped APIs, just right. 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/global-actor-isolation-refactor

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov

codecov Bot commented Aug 18, 2025

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilderSettings.swift (1)

14-22: Public API rename is fine; consider adding deprecated shims for smoother migration

Renaming to explicitGlobalActorIsolation is clearer. Since this is a public surface, consider temporary deprecated aliases to reduce churn for downstream users.

Add a deprecated passthrough property and initializer:

// Inside DeclBuilderSettings
@available(*, deprecated, message: "Use explicitGlobalActorIsolation instead.")
public var preferredGlobalActorIsolation: GlobalActorIsolation? {
    get { explicitGlobalActorIsolation }
    set { explicitGlobalActorIsolation = newValue }
}

@available(*, deprecated, message: "Use init(accessControlLevel:explicitGlobalActorIsolation:) instead.")
public init(
    accessControlLevel: AccessControlLevel,
    preferredGlobalActorIsolation: GlobalActorIsolation?
) {
    self.init(
        accessControlLevel: accessControlLevel,
        explicitGlobalActorIsolation: preferredGlobalActorIsolation
    )
}
Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilder.swift (2)

36-37: Drop redundant TypeSyntax wrapping.

extendedType.trimmed is already a TypeSyntax. The extra TypeSyntax(...) construction is unnecessary.

-            .extension(trimmedType: TypeSyntax(extendedType.trimmed)),
+            .extension(trimmedType: extendedType.trimmed),

25-32: Avoid shadowing trimmedType binding in the switch

In the switch over TypeDeclBuilderContext.current, the pattern name trimmedType shadows the surrounding property, which can be confusing. Consider renaming the bound value for clarity:

• File: Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilder.swift
Lines: 25–32

Suggested change:

-        case let .extension(trimmedType):
-            trimmedType
+        case let .extension(trimmedType: t):
+            t
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift (1)

21-27: Good switch to inlinableAccessControlLevel; avoid local shadowing of settings.

Logic change is correct. Minor readability nit: let settings = settings.accessControlLevel shadows the property name.

-        let settings = settings.accessControlLevel
+        let aclSettings = settings.accessControlLevel
         return basicDeclaration.inlinableAccessControlLevel(
-            inheritedBy: settings.inheritingDeclaration,
-            maxAllowed: settings.maxAllowed
+            inheritedBy: aclSettings.inheritingDeclaration,
+            maxAllowed: aclSettings.maxAllowed
         )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 42ff054 and f1cccd4.

📒 Files selected for processing (7)
  • Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift (1 hunks)
  • Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilderSettings.swift (1 hunks)
  • Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilder.swift (1 hunks)
  • Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilderContext.swift (1 hunks)
  • Sources/PrincipleMacros/Syntax/Extensions/WithModifiersSyntax.swift (1 hunks)
  • Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift (1 hunks)
  • Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (6)
Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift (3)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (1)
  • nonisolated (11-15)
Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (1)
  • globalActorIsolationPreference (67-85)
Sources/PrincipleMacros/Syntax/Extensions/WithAttributesSyntax.swift (1)
  • globalActor (11-18)
Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilderContext.swift (4)
Sources/PrincipleMacros/Builders/Declarations/Types/EnumDeclBuilder.swift (1)
  • typeDeclaration (16-21)
Sources/PrincipleMacros/Builders/Declarations/Types/StatefulDeclBuilder.swift (1)
  • typeDeclaration (16-21)
Sources/PrincipleMacros/Syntax/Custom/StatefulDeclSyntax.swift (2)
  • extension StructDeclSyntax: StatefulDeclSyntax {} (14-14)
  • extension ClassDeclSyntax: StatefulDeclSyntax {} (13-13)
Sources/PrincipleMacros/Builders/Declarations/Types/ClassDeclBuilder.swift (1)
  • typeDeclaration (16-21)
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilderSettings.swift (2)
Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (1)
  • globalActorIsolationPreference (67-85)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (1)
  • nonisolated (11-15)
Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift (3)
Sources/PrincipleMacros/Syntax/Extensions/WithModifiersSyntax.swift (1)
  • inlinableAccessControlLevel (46-73)
Sources/PrincipleMacros/Syntax/Extensions/WithAttributesSyntax.swift (1)
  • globalActor (11-18)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (1)
  • nonisolated (11-15)
Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilder.swift (4)
Sources/PrincipleMacros/Syntax/Extensions/TypeSyntax.swift (2)
  • standardized (65-74)
  • standardized (18-35)
Sources/PrincipleMacros/Builders/Declarations/Types/ClassDeclBuilder.swift (1)
  • typeDeclaration (16-21)
Sources/PrincipleMacros/Builders/Declarations/Types/StatefulDeclBuilder.swift (1)
  • typeDeclaration (16-21)
Sources/PrincipleMacros/Builders/Declarations/Types/EnumDeclBuilder.swift (1)
  • typeDeclaration (16-21)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift (4)
Sources/PrincipleMacros/Syntax/Extensions/WithAttributesSyntax.swift (1)
  • globalActor (11-18)
Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolationPreference.swift (1)
  • nonisolated (11-15)
Sources/PrincipleMacros/Syntax/Extensions/SyntaxProtocol.swift (1)
  • withTrailingSpace (11-36)
Sources/PrincipleMacros/Parameters/ParameterExtractor.swift (1)
  • globalActorIsolationPreference (67-85)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-and-test (macos)
🔇 Additional comments (6)
Sources/PrincipleMacros/Builders/Declarations/Types/TypeDeclBuilderContext.swift (1)

14-14: All .extension cases now use trimmedType: – no unlabeled .extension( usages were found.

Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift (1)

25-31: LGTM: inlinableAttribute returns a spaced attribute ready for inlining

Constructing AttributeSyntax from the trimmed type and appending a trailing space aligns with the “inlinable” usage elsewhere.

Tests/PrincipleMacrosTests/Parameters/ParameterExtractorTests.swift (1)

100-104: LGTM: assertion now validates the type-based isolation directly

Comparing trimmedType?.description to the expected isolation string aligns the test with the new type-centric API.

Sources/PrincipleMacros/Syntax/Extensions/WithModifiersSyntax.swift (1)

46-73: All references to accessControlLevel(inheritedBy:) have been updated
A repo-wide search for accessControlLevel( (excluding tests) only matched the local helpers and property accessors in WithModifiersSyntax.swift. There are no external call sites that need renaming.

Sources/PrincipleMacros/Builders/Declarations/Common/DeclBuilder.swift (2)

32-41: Global-actor derivation logic reads correctly.

Explicit isolation takes precedence, and fallback derives from the declaration attribute using a trimmed type. This is consistent with the new .isolated(trimmedType:) API.


42-44: Confirm intent to expose inheritedGlobalActorAttribute as public API.

New public surface area can affect semver. If this is only used internally (or for tests), consider lowering visibility; otherwise, adding a brief doc comment about when it returns nil would help consumers.

Do you want this property to be part of the public API? If not, I can provide a patch to make it internal and add doc comments.

Comment on lines 16 to 23
public var trimmedType: TypeSyntax? {
switch self {
case let .isolated(type):
type
case let .isolated(trimmedType):
trimmedType
case .nonisolated:
nil
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Bug: missing return statements in switch within computed property

The switch inside trimmedType omits return in each case and will not compile. Add explicit returns or rewrite without switch.

Apply one of the following:

Option A (minimal change):

     public var trimmedType: TypeSyntax? {
         switch self {
-        case let .isolated(trimmedType):
-            trimmedType
+        case let .isolated(trimmedType):
+            return trimmedType
         case .nonisolated:
-            nil
+            return nil
         }
     }

Option B (more concise):

-    public var trimmedType: TypeSyntax? {
-        switch self {
-        case let .isolated(trimmedType):
-            trimmedType
-        case .nonisolated:
-            nil
-        }
-    }
+    public var trimmedType: TypeSyntax? {
+        if case let .isolated(trimmedType) = self {
+            return trimmedType
+        }
+        return nil
+    }
🤖 Prompt for AI Agents
In Sources/PrincipleMacros/Syntax/Helpers/GlobalActorIsolation.swift around
lines 16 to 23, the computed property trimmedType uses a switch where each case
lacks an explicit return causing a compile error; fix by either adding explicit
returns (e.g., return trimmedType and return nil) in each case, or replace the
switch with a concise expression (for example use if case let .isolated(t) =
self { return t } else { return nil } or a single-line computed return using a
pattern match) so the property returns a TypeSyntax? value.

@NSFatalError NSFatalError merged commit 1da8325 into main Aug 18, 2025
7 of 9 checks passed
@NSFatalError NSFatalError deleted the feature/global-actor-isolation-refactor branch August 18, 2025 22:04
@coderabbitai coderabbitai Bot mentioned this pull request Nov 22, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant